from django.shortcuts import render
from django.http.response import HttpResponse

# Create your views here.
def set_session(request):

    request.session['username'] = 'username'

    return HttpResponse('set_session')

def get_session(request):
    # username = request.session['username']
    # username = request.session.get('name')
    del request.session['username']
    # request.session.flush()
    return HttpResponse('get_session')

def text(request):
    if request.method=='GET':
        return HttpResponse('get')
    else:
        return HttpResponse('post')

######################类视图定义
from django.views import View
class JDLogin(View):
    def get(self,request):
        return HttpResponse('get')

    def post(self,request):
        return HttpResponse('post')

    def delete(self,request):
        return HttpResponse('delete')

class CenterView(View):

    def get(self,request):
        islogin=False
        if islogin:
            #展示个人信息
            return HttpResponse('get')
        else:
            return HttpResponse('请登录')

    def post(self,request):
        islogin=False
        if islogin:
            #修改个人信息
            return HttpResponse('post')
        else:
            return HttpResponse('请登录')

##################类视图多继承重写dispatch
from django.contrib.auth.mixins import LoginRequiredMixin

# class Center_View(LoginRequiredMixin,View):
class Center_View(View,LoginRequiredMixin):

    def get(self, request):
        # islogin = False
        # if islogin:
        #     # 后期根据状态保持信息来判断
            return HttpResponse('get')
        # else:
        #     return HttpResponse('请登录')

    def post(self, request):
        # islogin = False
        # if islogin:
        #     # 修改个人信息
            return HttpResponse('post')
        # else:
        #     return HttpResponse('请登录')
#########################中间件

